package com.future.hedongjun.home.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.baselib.activity.BaseActivity;
import com.future.baselib.entity.BaseResponse;
import com.future.baselib.http.HttpRequest;
import com.future.hedongjun.R;
import com.future.hedongjun.home.adapter.CategoryAdapter;
import com.future.hedongjun.home.bean.CategoryBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CategoryActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private CategoryAdapter categoryAdapter;
    private ArrayList<CategoryBean> categoryBeans;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);
        ButterKnife.bind(this);
        setTitle("全部分类");

        getData();
        recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        categoryAdapter = new CategoryAdapter(categoryBeans);
        recyclerView.setAdapter(categoryAdapter);
        categoryAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CategoryBean item = categoryAdapter.getItem(position);
                ClassListActivity.launch(CategoryActivity.this, item.getCate_name(), item.getCourse_cate_id(),"", 2);
            }
        });

    }

    private void getData() {
        //http请求

//        categoryBeans = new ArrayList<>();
//        CategoryBean bean = new CategoryBean();
//        bean.id = "1";
//        bean.imgUrl = "http://seopic.699pic.com/photo/50025/2423.jpg_wh1200.jpg";
//        bean.name = "红茶";
//        categoryBeans.add(bean);
//        CategoryBean bean1 = new CategoryBean();
//        bean1.id = "2";
//        bean1.imgUrl = "http://seopic.699pic.com/photo/50025/2423.jpg_wh1200.jpg";
//        bean1.name = "绿茶";
//        categoryBeans.add(bean1);
//        CategoryBean bean2 = new CategoryBean();
//        bean2.id = "3";
//        bean2.imgUrl = "http://seopic.699pic.com/photo/50025/2423.jpg_wh1200.jpg";
//        bean2.name = "白茶";
//        categoryBeans.add(bean2);

//        new HttpRequest<CategoryResponse>()
//                .with(this)
//                .setApiCode("_threeclasslist_001")
//                .addSuccessListener(new HttpRequest.OnNetworkSuccess() {
//                    @Override
//                    public void onSuccess(BaseResponse response) {
//                        categoryAdapter.setNewData(((CategoryResponse) response).data);
//                    }
//                }).start(new CategoryResponse());
    }
}
